<include file='Common:header' />
<script src="__PUBLIC__/assets/js/jquery.form.js"></script>
<script src="__PUBLIC__/ueditor/ueditor.config.js" type="text/javascript"></script>
<script src="__PUBLIC__/ueditor/ueditor.all.js" type="text/javascript"></script>
<!-- /section:basics/navbar.layout -->
<div class="main-container" id="main-container">

    <!-- #section:basics/sidebar -->

    <include file='Common:left' />


    <!-- /section:basics/sidebar -->
    <div class="main-content">
        <div class="main-content-inner">
            <div class="page-content">



                <!--主题-->
                <div class="page-header">
                    <h1>
                        您当前操作
                        <small>
                            <i class="ace-icon fa fa-angle-double-right"></i>
                            添加分类
                        </small>
                    </h1>
                </div>


                <div class="row">
                    <div class="col-xs-12">
                        <form class="form-horizontal" name="form0" id="form0"  method="post" action="{:U('add_country_run')}"  enctype="multipart/form-data">

                            <!-- 图文列表+详情DIV开始 -->

                            <div class="form-group">
                                <label class="col-sm-4 control-label no-padding-right" for="form-field-1">国家地区名： </label>
                                <div class="col-sm-6">
                                    <input type="text" name="name" id="title"  placeholder="请填写分类名称"  class="col-xs-10 col-sm-3" />
                                    <span class="help-inline col-xs-12 col-sm-7">
												<span class="middle" id="resone1"></span>
											</span>
                                </div>
                            </div>
                            <div class="space-4"></div>


                            <div class="clearfix form-actions">
                                <div class="col-md-offset-3 col-md-9">
                                    <button class="btn btn-info" type="submit">
                                        <i class="ace-icon fa fa-check bigger-110"></i>
                                        保存
                                    </button>

                                    &nbsp; &nbsp; &nbsp;
                                    <button class="btn" type="reset">
                                        <i class="ace-icon fa fa-undo bigger-110"></i>
                                        重置
                                    </button>
                                </div>
                            </div>
                        </form>
                    </div>
                </div>




                <div class="hr hr-24"></div>

                <include file='Common:header_nav' />

            </div><!-- /.page-content -->
        </div>
    </div><!-- /.main-content -->

    <include file='Common:footer' />

</div><!-- /.main-container -->

</body>
</html>
<script>
    function backpic(picurl){
        $("#img0").attr("src",picurl);//还原修改前的图片
        $("input[name='file0']").val("");//清空文本框的值
    }
    $(function(){
        $('#form0').ajaxForm({
            beforeSubmit: checkForm, // 此方法主要是提交前执行的方法，根据需要设置
            success: complete, // 这是提交后的方法
            dataType: 'json'
        });
        function checkForm(){



            if( '' == $.trim($('#title').val())){
                layer.alert('国家地区名必填', {icon: 6}, function(index){
                    layer.close(index);
                    $('#title').focus();
                });
                return false;
            }

        }
        function complete(data){
            if(data.status==1){
                layer.alert(data.info, {icon: 6}, function(index){
                    layer.close(index);
                    window.location.href=data.url;
                });
            }else{
                layer.alert(data.info, {icon: 5}, function(index){
                    layer.close(index);
                });
            }
        }

    });

    $("#file0").change(function(){
        var filepath = $("input[name='classify_img']").val();
        var extStart = filepath.lastIndexOf(".");
        var ext = filepath.substring(extStart, filepath.length).toUpperCase();
        if (ext != ".PNG" && ext != ".GIF" && ext != ".JPG" && ext != ".JPEG") {
            alert("图片限于png,gif,jpeg,jpg格式");
            return false;
        }
        file_size = this.files[0].size;
        var size = file_size / 1024;
        if (size > 3072) {
            alert("上传的图片大小不能超过3M！");
            return false;
        }
        var objUrl = getObjectURL(this.files[0]) ;
        console.log("objUrl = "+objUrl) ;
        if (objUrl) {
            $("#img0").attr("src", objUrl) ;
        }
    }) ;
    //建立一個可存取到該file的url
    function getObjectURL(file) {
        var url = null ;
        if (window.createObjectURL!=undefined) { // basic
            $("#news_flag_vap").attr("checked", true);
            url = window.createObjectURL(file) ;
        } else if (window.URL!=undefined) { // mozilla(firefox)
            $("#news_flag_vap").attr("checked", true);
            url = window.URL.createObjectURL(file) ;
        } else if (window.webkitURL!=undefined) { // webkit or chrome
            $("#news_flag_vap").attr("checked", true);
            url = window.webkitURL.createObjectURL(file) ;
        }
        return url ;
    }
</script>
